<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="客户名称" prop="customerName">
                        <el-input v-model="dataForm.customerName" placeholder="客户名称"></el-input>
                </el-form-item>
                <el-form-item label="跟进时间" prop="followupTime">
                        <el-date-picker
                                v-model="dataForm.followupTime"
                                type="datetime"
                                placeholder="跟进时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="跟进方式（电话、邮件、面谈等）" prop="followupMethod">
                        <el-input v-model="dataForm.followupMethod" placeholder="跟进方式（电话、邮件、面谈等）"></el-input>
                </el-form-item>
                <el-form-item label="跟进结果（如达成意向、需要进一步沟通等）" prop="followupResult">
                        <el-input v-model="dataForm.followupResult" placeholder="跟进结果（如达成意向、需要进一步沟通等）"></el-input>
                </el-form-item>
                <el-form-item label="跟进人" prop="followupPerson">
                        <el-input v-model="dataForm.followupPerson" placeholder="跟进人"></el-input>
                </el-form-item>
                <el-form-item label="记录创建时间" prop="createTime">
                        <el-date-picker
                                v-model="dataForm.createTime"
                                type="datetime"
                                placeholder="记录创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="记录更新时间" prop="updateTime">
                        <el-date-picker
                                v-model="dataForm.updateTime"
                                type="datetime"
                                placeholder="记录更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="是否删除（0：未删除，1：已删除）" prop="isDeleted">
                        <el-input v-model="dataForm.isDeleted" placeholder="是否删除（0：未删除，1：已删除）"></el-input>
                </el-form-item>
                <el-form-item label="删除时间" prop="deleteTime">
                        <el-date-picker
                                v-model="dataForm.deleteTime"
                                type="datetime"
                                placeholder="删除时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="删除操作人" prop="deletePerson">
                        <el-input v-model="dataForm.deletePerson" placeholder="删除操作人"></el-input>
                </el-form-item>
                <el-form-item label="跟进内容，详细记录跟进的详细信息" prop="followupContent">
                        <el-input v-model="dataForm.followupContent" placeholder="跟进内容，详细记录跟进的详细信息"></el-input>
                </el-form-item>
                <el-form-item label="修改日志，记录修改的内容和时间" prop="modifyLog">
                        <el-input v-model="dataForm.modifyLog" placeholder="修改日志，记录修改的内容和时间"></el-input>
                </el-form-item>
                <el-form-item label="删除日志，记录删除的内容和时间" prop="deleteLog">
                        <el-input v-model="dataForm.deleteLog" placeholder="删除日志，记录删除的内容和时间"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    customerName: null,
                    followupTime: null,
                    followupMethod: null,
                    followupResult: null,
                    followupPerson: null,
                    createTime: null,
                    updateTime: null,
                    isDeleted: null,
                    deleteTime: null,
                    deletePerson: null,
                    followupContent: null,
                    modifyLog: null,
                    deleteLog: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
                    ],
                    customerName: [
                        { required: true, message: '客户名称不能为空', trigger: 'blur' }
                    ],
                    followupTime: [
                        { required: true, message: '跟进时间不能为空', trigger: 'blur' }
                    ],
                    followupMethod: [
                        { required: true, message: '跟进方式（电话、邮件、面谈等）不能为空', trigger: 'blur' }
                    ],
                    followupResult: [
                        { required: true, message: '跟进结果（如达成意向、需要进一步沟通等）不能为空', trigger: 'blur' }
                    ],
                    followupPerson: [
                        { required: true, message: '跟进人不能为空', trigger: 'blur' }
                    ],
                    createTime: [
                        { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
                    ],
                    updateTime: [
                        { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
                    ],
                    isDeleted: [
                        { required: true, message: '是否删除（0：未删除，1：已删除）不能为空', trigger: 'blur' }
                    ],
                    deleteTime: [
                        { required: true, message: '删除时间不能为空', trigger: 'blur' }
                    ],
                    deletePerson: [
                        { required: true, message: '删除操作人不能为空', trigger: 'blur' }
                    ],
                    followupContent: [
                        { required: true, message: '跟进内容，详细记录跟进的详细信息不能为空', trigger: 'blur' }
                    ],
                    modifyLog: [
                        { required: true, message: '修改日志，记录修改的内容和时间不能为空', trigger: 'blur' }
                    ],
                    deleteLog: [
                        { required: true, message: '删除日志，记录删除的内容和时间不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppCustomerFollowup/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appcustomerfollowup
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppCustomerFollowup/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>